package com.foxzzz.back.tracking;

import java.util.*;

// -
public class Solution47 {
    public List<List<Integer>> permuteUnique(int[] nums) {
        List<List<Integer>> result = new ArrayList<>();
        List<Integer> list = new ArrayList<>();
        Arrays.sort(nums);
        HashSet<String> hashSet=new HashSet<>();
        range(result, list, nums,new HashSet<>(),hashSet);

        return result;
    }
    public void range(List<List<Integer>> result, List<Integer> list, int[] nums,Set<Integer> set,Set<String> set1) {
        //
        if (list.size() == nums.length) {
            if(!set1.contains(list.toString())) {
                result.add(new ArrayList<>(list));
                set1.add(list.toString());
            }
        }
        for (int i = 0; i < nums.length; i++) {

            if (!set.contains(i)) {
                list.add(nums[i]);
                set.add(i);
                range(result, list, nums, set,set1);
                list.remove(list.size() - 1);
                set.remove(i);
            }
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution47().permuteUnique(new int[]{1,1,2}));
    }
    }
